home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / pump_src / setup / pasdvt.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-04-25  |  8.9 KB  |  405 lines

  1. {
  2.   PASDVT.TPU - TP(6.0) unit for interfacing to DEMOVT.EXE  //  ARM 12/93,4/94
  3.  
  4.   (based on original VTASM.INC by JCAB)
  5.  
  6.  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7.    Note: VTASM.INC nomenclature sounded a bit clumsy to me, so I decided
  8.    not to follow it too closely O:-)
  9.  
  10.    The equivalence between VTASM.INC procedures and VTDEMO.TPU ones is
  11.    as follows:
  12.  
  13.    VTDEMO.TPU          VTASM.INC
  14.    ==========          =========
  15.     VT_Init            InitMusic
  16.     VT_Poll            CallMusic
  17.     VT_AutoOff         VTDisconnectTimer
  18.     VT_AutoOn          VTConnectTimer
  19.     VT_Timer           VTGetTickCounter
  20.     VT_Start           VTBeginSync
  21.     VT_SyncStart       VTBeginSync + VTWaitForStart
  22.     VT_GoTo            VTJumpPos
  23.     VT_GetSem          VTCheckSemaphore (*)
  24.     VT_SetSem          VTSetSemaphore
  25.     VT_Resync          VTMiddleSync
  26.     VT_SetVolume       VTSetSoundVolume
  27.     VT_GetVolume       VTGetSoundVolume
  28.  
  29.     VT_Delay           (no equivalent)
  30.  
  31.  
  32. (*) vtasm.inc's VTCheckSemaphore compares semaphore bx with value al,
  33. while vtdemo.tpu's VT_GetSem simply returns the value of the semaphore
  34. and leaves any comparison up to you.
  35.  
  36.  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  37.  
  38. 4/94 -- New functions:
  39.  
  40.     VT_QueryCh       -- returns TRUE if note played since last query.
  41.     VT_ChStatus      -- returns channel's tone, instrument, and volume.
  42.  
  43.     VT_ChannelCount  -- returns number of channels
  44.     VT_CurrentPos    -- returns current pattern/note
  45.     VT_Abort         -- tells DVT to quit on exit
  46.  
  47. }
  48.  
  49. UNIT PASDVT;
  50.  
  51. Interface
  52.  
  53. { ==============================================================
  54.  
  55.                       T H E   P R O C ' S                                       }
  56.  
  57.   function  VT_Init : boolean;                { detect and initialize DEMOVT    }
  58.   procedure VT_Poll;                          { ≥ 50Hz DEMOVT manual polling    }
  59.   procedure VT_AutoOff;                       { switch to manual polling        }
  60.   procedure VT_AutoOn;                        { switch to auto (IRQ0) polling   }
  61.   function  VT_Timer : longint;               { get music timer count (50Hz)    }
  62.   procedure VT_Start;                         { setup to start playing          }
  63.   procedure VT_SyncStart;    { Like start, but then waits 1/2 sec till music sounds }
  64.   procedure VT_GoTo( pattern, note : byte );  { jump to given pattern/note within score }
  65.   function  VT_GetSem( sem : byte ) : byte;   { get semaphore "sem" value       }
  66.   procedure VT_SetSem( sem, va : byte );      { set semaphore "sem" to "va"     }
  67.   procedure VT_Resync( sem, pattern, note : byte ); { wait for sync point       }
  68.   procedure VT_SetVolume( level : byte );     { set volume level                }
  69.   function  VT_GetVolume : byte;              { get volume level                }
  70.  
  71.   procedure VT_Delay( h : word );             { delay h hundredths of a second  }
  72.                                               {  while still updating music     }
  73.  
  74.   function VT_QueryCh( ChanNo : byte ) : boolean;  { TRUE if new note     }
  75.   procedure VT_ChStatus( ChanNo : byte; var per : word; var inst, volu : byte);
  76.   function VT_ChannelCount : byte;                 { get # of channels    }
  77.   procedure VT_CurrentPos( var pat, note : byte ); { current pattern/note }
  78.   procedure VT_Abort;
  79.  
  80. { ==============================================================
  81.  
  82.      ...AND THINGS FOR ALL YOU SHOW-OFF DO-IT-YOURSELF TYPES  ;->
  83.                                                                         }
  84. Type
  85.   TChanData =
  86.     RECORD
  87.       Period  : WORD;
  88.       Ins     : BYTE;
  89.       Vol     : BYTE;
  90.     END;
  91.   TChansData = ARRAY[1..32] OF TChanData;
  92.   TChansTrig = ARRAY[1..32] OF BOOLEAN;
  93.  
  94. TYPE
  95.   TVTRunInfo =
  96.     RECORD
  97.  
  98.       { Out }
  99.  
  100.       Semaphores     : ARRAY[0..255] OF BYTE;
  101.       ChansTrig      : TChansTrig;
  102.  
  103.       NumChannels    : BYTE;
  104.  
  105.       CtrlEntryPoint : POINTER;
  106.  
  107.       TickCounter    : LONGINT;
  108.  
  109.       RegEntryPoint  : POINTER;
  110.  
  111.       ChansData      : TChansData;
  112.  
  113.       Pos            : BYTE;
  114.       Seq            : BYTE;
  115.  
  116.       fill2          : ARRAY[1..81] OF BYTE;
  117.  
  118.       { In }
  119.  
  120.       fill3       : ARRAY[1..3] OF BYTE;
  121.  
  122.       JumpNewPos  : BOOLEAN;
  123.       JumpPosSeq  : BYTE;
  124.       JumpPosNote : BYTE;
  125.  
  126.       Volume      : BYTE;
  127.  
  128.       Abort       : BOOLEAN;
  129.  
  130.       fill4       : ARRAY[1..248] OF BYTE;
  131.  
  132.     END;
  133.  
  134.   VT_PInfo = ^TVTRunInfo;
  135.   VT_RInfo =  TVTRunInfo;
  136.  
  137.   VTIdString = ARRAY [0..255] OF BYTE;
  138.  
  139. var
  140.   VT_Info    : VT_PInfo;    { points to VT_RInfo record within DEMOVT }
  141.   AppIDFound : ^VTIdString; { dunno, ask JCAB... ;-) }
  142.  
  143.  
  144.  
  145. Implementation
  146.  
  147. const
  148.   VTOK : boolean = False;  { = True if DEMOVT installed and initialized }
  149.  
  150. var
  151.   VTControl : procedure ( command : word );
  152.  
  153.                            { VTInfo^.VTCtrlEntry for quick access }
  154.                            { (hope DEMOVT never changes it!) }
  155.  
  156.  
  157. procedure CLI; inline( $fa );
  158. procedure STI; inline( $fb );
  159.  
  160. { // VT_init }
  161.  
  162. function VT_Init : boolean; assembler;
  163. Const
  164.   MagicAX    = $5654;  {'VT'}
  165.   MagicBX    = $5472;  {'Tr'}
  166.   MagicCX    = $6163;  {'ac'}
  167.   MagicXorBX = $6B65;  {'ke'}
  168.   MagicXorCX = $7220;  {'r '}
  169. asm
  170.   mov ax, MagicAX
  171.   mov bx, MagicBX
  172.   mov cx, MagicCX
  173.   xor di,di
  174.   mov es, di
  175.   int 2fh
  176.   xor dl,dl
  177.   and ax,ax
  178.   jnz @no
  179.   cmp bx, MagicBX xor MagicXorBX
  180.   jne @no
  181.   cmp cx, MagicCX xor MagicXorCX
  182.   jne @no
  183.  
  184.   inc dl                   { DEMOVT detected! }
  185.   mov [word ptr AppIdFound+2], es
  186.   mov [word ptr AppIdFound  ], di   { save this... but for what ? }
  187.  
  188.   les di, [es:di-4]
  189.   mov [word ptr VT_Info+2], es
  190.   mov [word ptr VT_Info], di
  191.  
  192.   les di, [es:di+256+33]  { read VTCtrlEntry vector }
  193.   mov [word ptr VTControl+2], es
  194.   mov [word ptr VTControl],   di   { ...and copy it to VTControl }
  195.  
  196. @no:
  197.   xor ah, ah
  198.   mov al, dl
  199.   mov [VTOK], al
  200. end;
  201.  
  202.  
  203. { // VT_Poll }
  204.  
  205. procedure VT_Poll;
  206. begin
  207.   if VTOK then VTControl( 2 );
  208. end;
  209.  
  210.  
  211. { // VT_AutoOff }
  212.  
  213. procedure VT_AutoOff;
  214. begin
  215.   if VTOK then VTControl( 1 );
  216. end;
  217.  
  218.  
  219. { // VT_AutoOn }
  220.  
  221. procedure VT_AutoOn;
  222. begin
  223.   if VTOK then VTControl( 0 );
  224. end;
  225.  
  226.  
  227. { // VT_Timer }
  228.  
  229. function  VT_Timer : longint;
  230. begin
  231.   if VTOK then begin
  232.     CLI;
  233.     VT_Timer := VT_Info^.TickCounter;
  234.     STI;
  235.   end else
  236.     VT_Timer := 0;
  237. end;
  238.  
  239.  
  240. { // VT_Start }
  241.  
  242. procedure VT_Start;
  243. begin
  244.   if VTOK then VTControl( 3 );
  245. end;
  246.  
  247.  
  248. { // VT_SyncStart }
  249.  
  250. procedure VT_SyncStart;
  251. begin
  252.   if VTOK then begin
  253.     VTControl( 3 );
  254.     CLI;
  255.     VT_Info^.TickCounter := 0;
  256.     STI;
  257.     repeat  VT_Poll  until  VT_Timer >= 25;   { 25/50ths = 1/2 second }
  258.     VT_Info^.TickCounter := 0;
  259.   end;
  260. end;
  261.  
  262.  
  263. { // VT_GoTo }
  264.  
  265. procedure VT_GoTo( pattern, note : byte );
  266. begin
  267.   if VTOK then with VT_Info^ do begin
  268.     JumpNewPos  := TRUE;
  269.     JumpPosSeq  := pattern;
  270.     JumpPosNote := note;
  271.   end;
  272. end;
  273.  
  274.  
  275. { // VT_GetSem }
  276.  
  277. function  VT_GetSem( sem : byte ) : byte;
  278. begin
  279.   if VTOK then
  280.      VT_GetSem := VT_Info^.Semaphores[ sem ]
  281.   else
  282.      VT_GetSem := 0;
  283. end;
  284.  
  285.  
  286. { // VT_SetSem }
  287.  
  288. procedure VT_SetSem( sem, va : byte );
  289. begin
  290.   if VTOK then VT_Info^.Semaphores[ sem ] := va;
  291. end;
  292.  
  293.  
  294. { // VT_Sync }
  295.  
  296. procedure VT_Resync( sem, pattern, note : byte );
  297. begin
  298.   if VTOK then begin
  299.     if VT_GetSem( sem ) = 0 then VT_Goto( pattern, note );
  300.     inc( sem );
  301.     repeat VT_Poll until VT_GetSem( sem ) <> 0;
  302.   end;
  303. end;
  304.  
  305.  
  306. { // VT_SetVolume }
  307.  
  308. procedure VT_SetVolume( level : byte );
  309. begin
  310.   if VTOK then VT_Info^.Volume := level;
  311. end;
  312.  
  313.  
  314. { // VT_GetVolume }
  315.  
  316. function  VT_GetVolume : byte;
  317. begin
  318.   if VTOK then
  319.     VT_GetVolume := VT_Info^.Volume
  320.   else
  321.     VT_GetVolume := 0;
  322. end;
  323.  
  324.  
  325. { // VT_Delay }
  326.  
  327. procedure VT_Delay( h : word );
  328. var l : longint;
  329. begin
  330.   if VTOK then begin
  331.     l := VT_Timer + h shr 1;
  332.     repeat VT_Poll until VT_Timer >= l;
  333.   end;
  334. end;
  335.  
  336.  
  337. { // VT_QueryCh }
  338.  
  339. function VT_QueryCh( ChanNo : byte ) : boolean;
  340. begin
  341.   VT_QueryCh := false;
  342.   if VTOK then
  343.   if VT_Info^.ChansTrig[ ChanNo ] then begin
  344.      VT_QueryCh := true;
  345.      VT_Info^.ChansTrig[ ChanNo ] := false;
  346.   end;
  347. end;
  348.  
  349.  
  350. { // VT_ChStatus }
  351.  
  352. procedure VT_ChStatus( ChanNo : byte; var per : word; var inst, volu : byte);
  353. begin
  354.   if VTOK then
  355.     with VT_Info^.ChansData[ ChanNo ] do begin
  356.       per  := period;
  357.       inst := ins;
  358.       volu := vol;
  359.     end
  360.   else begin
  361.     per  := 0;
  362.     inst := 0;
  363.     volu := 0;
  364.   end;
  365. end;
  366.  
  367.  
  368. { // VT_Channels }
  369.  
  370. function VT_ChannelCount : byte;
  371. begin
  372.   if VTOK then
  373.     VT_ChannelCount := VT_Info^.NumChannels
  374.   else
  375.     VT_ChannelCount := 0;
  376. end;
  377.  
  378.  
  379. { // VT_CurrentPos }
  380.  
  381. procedure VT_CurrentPos( var pat, note : byte );
  382. begin
  383.   if VTOK then
  384.     with VT_Info^ do begin
  385.       pat  := seq;
  386.       note := pos;
  387.     end
  388.   else begin
  389.     pat  := 0;
  390.     note := 0;
  391.   end;
  392. end;
  393.  
  394.  
  395. { // VT_Abort }
  396.  
  397. procedure VT_Abort;
  398. begin
  399.   if VTOK then VT_Info^.Abort := true;
  400. end;
  401.  
  402.  
  403. END.
  404.  
  405.